package com.aiju.cash.core.api;

import com.aiju.app.config.ConfigManager;
import com.aiju.utils.L;
import com.aiju.utils.PriceUtil;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;


/**
 * @author: 佐为
 * @date: 2016-12-06 15:48
 * @version: V1.0
 * @Description: 付款
 */
public class PayApi {

    //private String base = "https://trade.ecbao.cn";
    //private String base = "http://16794ui705.iok.la:29890";
    private String base =ConfigManager.getInstance().INIT_PAY_HOST;
    /**
     * 支付宝支付
     */
    private String qrCodePay = base + "/zfbpay/qrCodePay";
    private String barCodePay = base + "/zfbpay/barCodePay";

    /**
     * 现金支付
     */
    private String pay = base + "/cash/pay";

    /**
     * 微信支付
     */
    private String wxQrCodePay = base + "/wxpay/qrCodePay";
    private String wxBarCodePay = base + "/wxpay/barCodePay";

    private String token = ConfigManager.getInstance().getUser().getToken();

    /**
     * 扫描
     */
    public void qrCodePay(int type, String storeId, String subject, String price,
                          String sumPrice, String operatorId, String operatorName, String privType, String privPrice,
                          String shouldPrice, String actualPrice, String changePrice,
                          String roundPrice, String detail, StringCallback callback) {
        String url = "";
        if (type == 0) {
            url = qrCodePay;
            L.d("支付宝：" + price);
        } else {
            url = wxQrCodePay;
            L.d("微信：" + price);
        }
        OkHttpUtils.post()
                .url(url)
                .addParams("storeId", storeId)
                .addParams("subject", subject)
                .addParams("price", price)
                .addParams("sumPrice", sumPrice)
                .addParams("operatorId", operatorId)
                .addParams("operatorName", operatorName)
                .addParams("privType", privType)
                .addParams("privPrice", privPrice)
                .addParams("shouldPrice", shouldPrice)
                .addParams("actualPrice", actualPrice)
                .addParams("changePrice", changePrice)
                .addParams("roundPrice", PriceUtil.formatDouble(roundPrice))
                .addParams("detail", detail)
                .addParams("token", token)
                .build()
                .execute(callback);
    }

    /**
     * 现金
     */
    public void pay(String storeId, String subject, String price,
                    String sumPrice, String operatorId, String operatorName, String privType, String privPrice,
                    String shouldPrice, String actualPrice, String changePrice,
                    String roundPrice, String memberPhone, String detail, StringCallback callback) {

        OkHttpUtils.post()
                .url(pay)
                .addParams("storeId", storeId)
                .addParams("subject", subject)
                .addParams("price", price)
                .addParams("sumPrice", sumPrice)
                .addParams("operatorId", operatorId)
                .addParams("operatorName", operatorName)
                .addParams("privType", privType)
                .addParams("privPrice", privPrice)
                .addParams("shouldPrice", shouldPrice)
                .addParams("actualPrice", actualPrice)
                .addParams("changePrice", changePrice)
                .addParams("roundPrice", roundPrice)
                .addParams("memberPhone", memberPhone)
                .addParams("detail", detail)
                .addParams("token", token)
                .build()
                .execute(callback);
        L.d("会员手机号：" + memberPhone);
    }

    /**
     * 条码支付接口
     */
    public void barCodePay(int type, String storeId, String authCode, String subject, String price,
                           String sumPrice, String operatorId, String operatorName, String privType, String privPrice,
                           String shouldPrice, String actualPrice, String changePrice,
                           String roundPrice, String detail, StringCallback callback) {
        String url = "";
        if (type == 0) {
            url = barCodePay;
            L.d("支付宝：" + price);
        } else {
            url = wxBarCodePay;
            L.d("微信：" + price);
        }
        OkHttpUtils.post()
                .url(url)
                .addParams("storeId", storeId)
                .addParams("authCode", authCode)
                .addParams("subject", subject)
                .addParams("price", price)
                .addParams("sumPrice", sumPrice)
                .addParams("operatorId", operatorId)
                .addParams("operatorName", operatorName)
                .addParams("privType", privType)
                .addParams("privPrice", privPrice)
                .addParams("shouldPrice", shouldPrice)
                .addParams("actualPrice", actualPrice)
                .addParams("changePrice", changePrice)
                .addParams("roundPrice", PriceUtil.formatDouble(roundPrice))
                .addParams("detail", detail)
                .addParams("token", token)
                .build()
                .execute(callback);
    }


}
